package com.bit.secretfolder;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class SecretDB {

	private WordDBHelper mHelper;
	private SQLiteDatabase db;

	public SecretDB(Context context) {
		mHelper = new WordDBHelper(context);
	}

	public void insert(String query) {
		db = mHelper.getWritableDatabase();
		db.execSQL(query);
		mHelper.close();
	}

	public void delete(String query) {
		db = mHelper.getWritableDatabase();
		db.execSQL(query);
		mHelper.close();
	}

	public void update(String query) {
		db = mHelper.getWritableDatabase();
		db.execSQL(query);
		mHelper.close();
	}

	public String find(String password) {
		db = mHelper.getReadableDatabase();
		String value = db.rawQuery(password, null).toString();

		return value;
	}

	public ArrayList<ArrayList<String>> select(String query) {
		db = mHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(query, null);

		ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();
		while (cursor.moveToNext()) {
			ArrayList<String> item = new ArrayList<String>();
			for (int i = 0; i < cursor.getColumnCount(); i++) {
				item.add(cursor.getString(i));
			}
			result.add(item);
		}
		cursor.close();
		mHelper.close();

		return result;
	}

}
